package com.example.personaldoofadmin.foodstoragedatabase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class StorageSQLiteHelper extends SQLiteOpenHelper
{
    /**
     * @author Lars Loser
     * 
     *         Create a helper object to create, open, and/or manage a database.
     * 
     * 
     * @param context
     *            to use to open or create the database
     * @param name
     *            name of the database file, or null for an in-memory database
     * @param factory
     *            to use for creating cursor objects, or null for the default
     * @param version
     *            number of the database (starting at 1)
     */

    // attributes

    public static final String TABLE_NAME = "food_storage";// name of the table

    public static final String FOOD_ID = "food_id"; // primary key (identifies
                                                    // every entry with an
                                                    // unique id)

    public static final String FOOD_NAME = "name"; // name of the food

    public static final String FOOD_DESC = "description"; // description

    private static final String DATABASE_NAME = "food_storage.db"; // name of
                                                                   // the
                                                                   // database

    private static final int DATABASE_VERSION = 1; // version number

    private static final String CREATE = "create table " + TABLE_NAME + " (" + FOOD_ID + " integer primary key autoincrement, " + FOOD_NAME + " text not null, " + FOOD_DESC + " text not null);";

    public StorageSQLiteHelper(Context context)
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    /**
     * Called when the database is created for the first time. This is where the
     * creation of tables and the initial population of the tables should
     * happen.
     * 
     * @param db
     *            java representation of the database
     */

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL(CREATE);
    }

    /**
     * Called when the database needs to be upgraded.
     * 
     * @param db
     *            java representation of the database
     * @param newVersion
     *            new database version
     */

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {

    }

}
